package com.excilys.formation.projet.ebanking.modele;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "COMPTE")
public class Compte {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "CPT_ID")
	private int id;
	
	@Column(name = "CPT_NUMERO")
	private String numero;
	
	@Column(name = "CPT_SOLDE_COURANT")
	private double soldeCourant;
	
	@Column(name = "CPT_LIBELLE")
	private String libelle;
	
	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name = "CPT_ID")
	private List<Operation> operations;
	
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(name = "REL_UTILISATEUR_COMPTE", joinColumns = @JoinColumn(name = "CPT_ID"), inverseJoinColumns = @JoinColumn(name = "UTL_ID"))
	private List<Utilisateur> utilisateurs;
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public String getNumero() {
		return numero;
	}
	
	public void setNumero(String numero) {
		this.numero = numero;
	}
	
	public double getSoldeCourant() {
		return soldeCourant;
	}
	
	public void setSoldeCourant(double soldeCourant) {
		this.soldeCourant = soldeCourant;
	}
	
	public String getLibelle() {
		return libelle;
	}
	
	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}
	
	public void setOperations(List<Operation> operations) {
		this.operations = operations;
	}
	
	public List<Operation> getOperations() {
		return operations;
	}
	
	public void setUtilisateurs(List<Utilisateur> utilisateurs) {
		this.utilisateurs = utilisateurs;
	}
	
	public List<Utilisateur> getUtilisateurs() {
		return utilisateurs;
	}
	
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return numero.hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj != null && obj instanceof Compte) {
			Compte compte = (Compte) obj;
			return numero.equals(compte.numero);
		}
		else
			return false;
	}
	
}
